<?php

/**
 * 默认关注管理 -- 推荐提交程序
 * 
 * @copyright caijian
 * @since 2012-03-20
 */




include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	
	// id
	cgi::both($g_cgival["ids"], "ids", '');
	
	// op
	cgi::both($g_cgival["op"], "op", "");
	
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show;
	
	$ids = explode(',',$g_cgival["ids"]);
	$op = $g_cgival["op"];

	if (! $op || ! $ids )
	{
		throw new Exception("参数错误！");
	}

	if ( $op != '1' && $op != '-1' ) {
		throw new Exception("参数错误！");
	}

	// 拿到当前站点的site_id
	$site_id = admin::admin_get_user_site_id();
	$admin_id = admin::admin_get_login_uid();
	$admin_name = admin::admin_get_login_user_name();

//  	$db->debug = true;
	
	$db = new db_food_user_daren();
	$fuser = new mod_food_user();
	$admin_log = new admin_log();

	// 判断


	foreach ($ids  as $uid) {

		if(! $uid) continue;

		$daren = $fuser->get_food_user_info($uid);
		if ($daren['error'] != '0') {
			throw new Exception("达人不存在:".$daren['errmsg'] . '('.$uid.')');
		}

		if ($op == '1') {  // 添加关注
			$db->admin_update_food_user_daren_status($uid, $site_id, 1, $admin_id, $admin_name);
			$admin_log->admin_insert_log_info($admin_id, $site_id, 14, "推荐 专辑达人uid={$uid}");
		} else { // 删除推荐
			$db->admin_update_food_user_daren_status($uid, $site_id, 0, $admin_id, $admin_name);
			$admin_log->admin_insert_log_info($admin_id, $site_id, 14, "取消推荐 专辑达人uid={$uid}");
		}
		
	
	}
}

try
{

	admin_check_login();
// 	admin_check_user_priv("foodv2/main_nav.php");
	
	check_cgi_pro();
	get_data();
	
	$g_show["error"] = 0;
	$g_show["errmsg"] = "成功";	

}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_show;
	
	echo json_encode($g_show);
}

?>